package leetcode;

import java.util.Arrays;

/**
 * @Project : ProgrammingExercises
 * @Package : Leetcode
 * @File : Q2475.java
 * @Author : WangRuoyu
 * @Date 2023/2/24 11:08
 */
public class Q2475 {
    public int unequalTriplets(int[] nums) {
        Arrays.sort(nums);
        int[] f = new int[nums.length];

        for (int i = 2; i < nums.length; ++i) {
            int res = 0;
            int index = i - 1;
            while ((index >= 0) && (nums[index] == nums[i])) {
                index--;
            }
            if (index == -1) {
                f[i] = 0;
            } else {
                for (int j = 0; j <= index; ++j) {
                    for (int k = j + 1; k <= index; ++k) {
                        if (nums[j] != nums[k]) {
                            res++;
                        }
                    }
                }
                f[i] = f[i - 1] + res;
            }
        }

        return f[nums.length - 1];
    }

    public static void main(String[] args) {
        Q2475 sl = new Q2475();
//        int[] nums = {1, 3, 1, 2, 4};
//        int[] nums = {4, 4, 2, 4, 3};
        int[] nums = {1, 1, 1, 1, 1};
        System.out.println(sl.unequalTriplets(nums));
    }
}
